﻿using System.Collections;
using System.Collections.Generic;

namespace SyncUdp.Event
{
    using SyncUdp.Enum;
    using SyncUdp.Interface;
    using System;

    namespace NetworkEvent
    {
        /// <summary>
        /// 作为字段的网络事件类
        /// </summary>
        public class NetworkEventField
        {
            public JoinGameEvent joinGameEventArgs;
            public ClientInputsEvent clientInputsEventArgs;
            public ServerDispathesInputsEvent serverDispathesEventArgs;
            public ServerReissuesFramesEvent serverReissuesFramesEventArgs;
        }

        /// <summary>
        /// 作为消息进行通信的网络事件
        /// </summary>
        [Serializable]
        public struct NetworkEventToSend
        {
            public NetworkEventType eventType;
            public TryJoinningGameEvent tryJoinningGameEvent;
            public JoinGameEvent joinGameEventArgs;
            public ClientInputsEvent clientInputsEventArgs;
            public ServerDispathesInputsEvent serverDispathesEventArgs;
            public ServerReissuesFramesEvent serverReissuesFramesEventArgs;
        }

        [Serializable]
        public class TryJoinningGameEvent : INetworkEventArgs
        {
            public int playerId;
            public string playerName;

            public JoinGameErrorType errorType;

            /// <summary>
            /// 玩家 ID（如果成功连接，则此列表不为空）
            /// </summary>
            public List<int> otherPlayers;

            /// <summary>
            /// 玩家名字（如果成功连接，则此列表不为空）
            /// </summary>
            public List<string> otherPlayersName;
        }

        [Serializable]
        public class JoinGameEvent : INetworkEventArgs
        {
            public int playerId;

            public string playerName;
        }

        [Serializable]
        public class ClientInputsEvent : INetworkEventArgs
        {
            /// <summary>
            /// 代表客户端 Id 的玩家 Id
            /// </summary>
            public int id;
            public string name;
            public Model.PlayerInputs inputs;

            public int clientFrame;
            public bool isDisconnected;
        }

        [Serializable]
        public class ServerDispathesInputsEvent : INetworkEventArgs
        {
            public int serverFrame;
            public List<ClientInputsEvent> allClientInputs;
        }

        /// <summary>
        /// 服务器重新发送帧数
        /// </summary>
        [Serializable]
        public class ServerReissuesFramesEvent : INetworkEventArgs
        {
            public List<List<ClientInputsEvent>> reissuedInputs;
        }
    }
}
